package com.mdd.front.service.impl.yangyangLeadingEnterprise;

import com.mdd.common.entity.yangyangLeadingEnterprise.TAppCorporateFinanceApplicationRecord;
import com.mdd.common.entity.yangyangLeadingEnterprise.common.JsonReturn;
import com.mdd.common.entity.yangyangLeadingEnterprise.param.CorporateFinanceRecordParam;
import com.mdd.common.mapper.yangyangLeadingEnterprise.TAppCorporateFinanceApplicationRecordMapper;
import com.mdd.common.mapper.yangyangLeadingEnterprise.TAppCorporateFinanceMapper;
import com.mdd.common.mapper.yangyangLeadingEnterprise.TAppEnterpriseMapper;
import com.mdd.common.mapper.yangyangLeadingEnterprise.TAppUserMapper;
import com.mdd.front.service.yangyangLeadingEnterprise.ITAppCorporateFinanceApplicationRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 企业融资申请记录实现类
 * @author LikeAdmin
 */
@Service
public class TAppCorporateFinanceApplicationRecordServiceImpl implements ITAppCorporateFinanceApplicationRecordService {
        
    @Resource
    TAppCorporateFinanceApplicationRecordMapper tAppCorporateFinanceApplicationRecordMapper;

    @Resource
    TAppUserMapper appUserMapper;

    @Resource
    TAppEnterpriseMapper appEnterpriseMapper;

    @Resource
    TAppCorporateFinanceMapper appCorporateFinanceMapper;

    /**
     * 企业融资申请记录新增
     * @param param 企业融资申请记录新增参数
     * @return
     */
    @Override
    public String addCorporateFinanceApplicationRecord(CorporateFinanceRecordParam param) {
        Long userId = param.getUserId();
        Integer enterpriseId = param.getEnterpriseId();
        Integer corporateFinanceId = param.getCorporateFinanceId();
        if(userId==null || enterpriseId==null || corporateFinanceId==null){
            return JsonReturn.fail("必传参数不能为空！",40001).toJsonStr();
        }
        TAppCorporateFinanceApplicationRecord model = new TAppCorporateFinanceApplicationRecord();
        model.setUserId(userId);
        model.setUserName(appUserMapper.selectById(userId).getNickname());
        model.setEnterpriseId(param.getEnterpriseId());
        model.setEnterpriseName(appEnterpriseMapper.selectById(enterpriseId).getEnterpriseName());
        model.setCorporateFinanceId(param.getCorporateFinanceId());
        model.setCorporateFinanceName(appCorporateFinanceMapper.selectById(corporateFinanceId).getName());
        model.setStatus(1);
        model.setCreateTime(new Date());
        model.setUpdateTime(new Date());
        tAppCorporateFinanceApplicationRecordMapper.insert(model);
        return JsonReturn.success().toJsonStr();
    }

}
